//
//  TabBarController.m
//  WisdomZhuHai
//
//  Created by yewei on 13-8-21.
//  Copyright (c) 2013年 wyd. All rights reserved.
//

#import "TabBarController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FiveViewController.h"
#import "Common.h"
#import "TransforController.h"

@interface TabBarController (){
}
@property(nonatomic, assign)BOOL isInitMemberCenter;
@end

@implementation TabBarController

-(void)dealloc
{
    [super dealloc];
}

-(void)buildView
{
    FirstViewController *first = [[FirstViewController alloc]init];
//    ThirdViewController *fourth = [[ThirdViewController alloc]init];
    ThirdViewController *fourth = [TransforController sharedInstanceOfThirdViewController];
    FourthViewController *second = [[FourthViewController alloc]init];
//    SecondViewController *third = [[SecondViewController alloc]init];
    SecondViewController *third = [TransforController sharedInstanceOfSecondViewController];
//    FiveViewController *five = [[FiveViewController alloc]init];
    
    UINavigationController *firstNv = [[UINavigationController alloc]initWithRootViewController:first];
    UINavigationController *secondNv = [[UINavigationController alloc]initWithRootViewController:second];
    UINavigationController *thirdNv = [[UINavigationController alloc]initWithRootViewController:third];
    UINavigationController *fourthNv = [[UINavigationController alloc]initWithRootViewController:fourth];
//    UINavigationController *fiveNv = [[UINavigationController alloc]initWithRootViewController:five];
    self.viewControllers = [NSArray arrayWithObjects:firstNv,thirdNv,secondNv,fourthNv,nil];
    self.delegate =self;
    //    self.view.backgroundColor = [UIColor blackColor];
    //    self.selectedIndex = 0;
    //   first.tabBarItem.badgeValue = @"new";
    [first release];
//    [second release];
    [third release];
    [fourth release];
//    [five release];
    [firstNv release];
    [secondNv release];
    [thirdNv release];
    [fourthNv release];
//    [fiveNv release];

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.isInitMemberCenter = false;
	// Do any additional setup after loading the view.
//    self.delegate = self;
    [self buildView];
}

//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    return  UIInterfaceOrientationIsPortrait( interfaceOrientation );
//}
//
//// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
//- (NSUInteger) supportedInterfaceOrientations{
//#ifdef __IPHONE_6_0
//    // return UIInterfaceOrientationMaskAllButUpsideDown;
//    return UIInterfaceOrientationMaskPortrait;
//#endif
//}
//
//- (BOOL) shouldAutorotate {
//    return NO;
//}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -tabBar delegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
   // viewController.tabBarItem.badgeValue = @"new";
//    MLNavigationController *nv = (MLNavigationController *)viewController;
//    [nv clearBackGroudView];
    NSLog(@"%s || selected:%d", __FUNCTION__, tabBarController.selectedIndex);
    if(tabBarController.selectedIndex == 2){
        [[TransforController sharedInstanceOfToolsViewController]reloadData];
    }else if(tabBarController.selectedIndex == 3 && self.isInitMemberCenter == false){
        self.isInitMemberCenter = true;
    }
}


@end
